#!/usr/bin/env python
#-*- coding:UTF-8 -*-
#####################################################
# Author: Jiaion - jiaion21@gmail.com
# Last modified:  2011-01-08 02:16
# Filename:  views.py
#####################################################
from django.http import HttpResponse
from django.http import HttpResponseRedirect
from Context.Render import render
from django.contrib.auth.decorators import login_required
from Jiaion.models import REG
from django.conf import settings
import Jredis as redis

@login_required()
def Usermg(request):
    return render('usermg.html',{},request)

@login_required()
def Userappar(request):
    if request.method == 'POST':
      if request.REQUEST.get('Clear'):
        APPALL = request.POST
        try :
          for i in APPALL:
            if APPALL.get(i,'') == 'True':
              REG.objects.get(USER=i).delete()
        #except UnicodeEncodeError:
        #  pass
        except :
          pass
        NEWREG = REG.objects.filter(APPROVAL=0)
        return render('usermg.html',{'approval':True,'new':NEWREG,},request)
      else:
        APPALL = request.POST
        try :
          for i in APPALL:
            if APPALL.get(i,'') == 'True':
              P = REG.objects.get(USER=i)
              P.APPROVAL = 1
              P.save()
              value = {'UserName':i,'Mail':u'您的系统密码为','Type':'SendUser','Pass':P.PASS}
              redis.lpushs("USERREG",value)
        except UnicodeEncodeError:
          pass
        NEWREG = REG.objects.filter(APPROVAL=0)
        return render('usermg.html',{'approval':True,'new':NEWREG,},request)
    else :
      NEWREG = REG.objects.filter(APPROVAL=0)
      return render('usermg.html',{'approval':True,'new':NEWREG,},request)

